// 3-bind bind1st bind2nd
#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
using namespace std::placeholders;


class Test
{
private:
  /* data */
public:
  int a = 5;
  Test();
  ~Test();
  void func1(int a)
  {
    std::cout << "a: " << a << std::endl;
  }
  void func2(int a, int b)
  {
    std::cout << "a: " << a << " b: " << b << std::endl;
  }
};

Test::Test(/* args */)
{
}

Test::~Test()
{
}

// 全局函数
void func(int a, int b)
{
  std::cout << "a: " << a << " b: " << b << std::endl;
}

int main(void)
{
  // 普通方法不能用，必须继承 struct binary_function
  // auto fun1 = std::bind1st(func,100);
  // std::function<void(int)> fun1 = std::bind1st(func,100);
  // fun1(20);

  
  std::vector<int> nums;
  nums.reserve(10);
  for(int i = 0 ; i < 10 ; i++){
    nums.push_back(i+1);
  }

  // 统计大于5的数的个数
  int count = std::count_if(nums.begin(),nums.end(),std::bind1st(std::greater<int>(),5));
  std::cout << "count: " << count << std::endl; // 4

  // 统计小于7的数的个数
  count = std::count_if(nums.begin(),nums.end(),std::bind2nd(std::less<int>(),7));
  std::cout << "count: " << count << std::endl; // 6

  
  printf("------------end---------------\n");
  return 0;
}